import { State } from "framework/FSM/AState";
import { ActionArgHelper } from "../../ActionManager/ActionArgHelper";
 

/*
待机状态，当PC store满了的时候存储OPS
*/
export class State_Waitting<T extends IStateArg<PowerCreep>>  extends State<T>
{

    public  getActions(arg:T):Action[]
    {
        const core = arg.entity.getEntity("CoreEntity");

        if( arg.entity)
        {
            if(arg.entity.store.getFreeCapacity() == 0)
            {
                const ops_amount = arg.entity.store.getUsedCapacity(RESOURCE_OPS);
                const storeres = {resourceType:RESOURCE_OPS,amount:ops_amount};
                const storeobjs = core.getStores(storeres);
                if(storeobjs.length>0)
                {
                    const store =storeobjs[0] ;
                    if(arg.entity.pos.distance(store.pos)>1)
                    {
                        // const motoarg:IMoveArg={creepid:"" as Id<Creep>,pos: store.pos,range:1,opt:{}};
                        // arg.entity.moveTo(motoarg);
                        return [ActionArgHelper.actionMoveto(arg.entity,{pos: store.pos,range:1},{})]
                    }
                    else
                    {
                        arg.entity.transfer( store,storeres.resourceType,storeres.amount);
                    }
                }

            }
        }
        else
        {
            // global.Log.Error(`此房间 ${ arg.entity.MountRoom} 没有powerSpawn`);
            // arg.entity.log ("info",` PC任务 enableroom  挂载房间的控制器没有${arg.entity.memory.OwnerRoom}`);
        }

        return [];
    }

}
